
# export GOROOT=/usr/local/go/bin/go
# export PATH=$PATH:$GOROOT/bin
# export GOPATH=/root/go
export GOPROXY=https://goproxy.cn
# export PATH := $(GOPATH)/bin:$(PATH)
export GOPROXY=https://goproxy.cn
export GO111MODULE=on


LDFLAGS		:= -s -w
BUILD_VERSION	:= $(shell git describe --tags `git rev-list --tags --max-count=1`)
BUILD_TIME	:= $(shell date "+%F %T")
BUILD_NAME	:= cmdb-agent
GIT_COMMIT	:= $(shell git rev-parse HEAD)
SOURCE		:= .
TARGET_DIR	:= ./scripts/build/

all: deps test build

deps:
	@echo "#########更新依赖##########"
	$(shell if [ ! -d $(TARGET_DIR) ]; then  mkdir -p $(TARGET_DIR) ; fi)
	/usr/local/go/bin/go mod download
	/usr/local/go/bin/go mod tidy

test:
	@echo "########代码格式化#########"
	/usr/local/go/bin/go fmt $(go list ./... | grep -v /vendor/)
	@echo "########代码格式化#########"
	/usr/local/go/bin/go vet $(go list ./... | grep -v /vendor/)
#	@echo "##########竞争检查#########"
#	CGO_ENABLED=1 go test -race $(go list ./... | grep -v /vendor/)


build:
	@echo "##########构建upload123程序###########"
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
        /usr/local/go/bin/go build -trimpath -ldflags "${LDFLAGS} \
      -X 'dfx_cmdb/cmdb-agent/version.BuildVersion=${BUILD_VERSION}' \
      -X 'dfx_cmdb/cmdb-agent/version.BuildTime=${BUILD_TIME}' \
      -X 'dfx_cmdb/cmdb-agent/version.GitCommit=${GIT_COMMIT}'" \
      -o ${TARGET_DIR}${BUILD_NAME} ${SOURCE} 